#include "sql_compiler_cpp/Lexer.h"
#include "sql_compiler_cpp/Parser.h"
#include <iostream>

int main() {
    std::string sql = "CREATE TABLE users (id INT);";

    std::cout << "Testing SQL: " << sql << std::endl;

    try {
        // 词法分析
        MiniDB::Lexer lexer(sql);
        auto tokens = lexer.tokenize();

        std::cout << "Tokens:" << std::endl;
        for (size_t i = 0; i < tokens.size(); ++i) {
            const auto& token = tokens[i];
            if (token.type != MiniDB::TokenType::EOF_TOKEN) {
                std::cout << "  " << i << ": Token(";
                switch (token.type) {
                    case MiniDB::TokenType::CREATE: std::cout << "CREATE"; break;
                    case MiniDB::TokenType::TABLE: std::cout << "TABLE"; break;
                    case MiniDB::TokenType::IDENTIFIER: std::cout << "IDENTIFIER"; break;
                    case MiniDB::TokenType::INT: std::cout << "INT"; break;
                    case MiniDB::TokenType::LPAREN: std::cout << "LPAREN"; break;
                    case MiniDB::TokenType::RPAREN: std::cout << "RPAREN"; break;
                    case MiniDB::TokenType::SEMICOLON: std::cout << "SEMICOLON"; break;
                    default: std::cout << static_cast<int>(token.type); break;
                }
                std::cout << ", '" << token.value << "', line=" << token.line
                          << ", col=" << token.column << ")" << std::endl;
            }
        }

        // 语法分析
        std::cout << "\nParsing..." << std::endl;
        MiniDB::Parser parser(tokens);
        auto statements = parser.parse();

        std::cout << "Successfully parsed " << statements.size() << " statements!" << std::endl;

    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}
